//
//  StatusForwardCell.swift
//  SinaMicroblog
//
//  Created by 唐绍禹 on 15/8/9.
//  Copyright © 2015年 唐绍禹. All rights reserved.
//

import UIKit

class StatusForwardCell: StatusCell {
    
    override var status: Status? {
        didSet {
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            
            forwardLabel.text = "@" + name + ":" + text
        }
    }
    
    override func setupUI() {
        super.setupUI()
        
        //添加按钮
//        contentView.addSubview(backgroundBtn)
        contentView.insertSubview(backgroundBtn, belowSubview: pictureView)
        contentView.insertSubview(forwardLabel, aboveSubview: backgroundBtn)
        
        //设置布局
        backgroundBtn.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -statusCellControlMargin, y: statusCellControlMargin))
        backgroundBtn.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        //转发文本
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backgroundBtn, size: nil, offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))
        
        //配图视图设置约束
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: statusCellControlMargin))
        pictureHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureWithCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureTopCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)
        
    }
    
    private lazy var forwardLabel: UILabel = {
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
        label.numberOfLines = 0;
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * statusCellControlMargin

        return label
    }()
    
    private lazy var backgroundBtn: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        return button
    }()
}
